package com.xxx.service;

import java.util.Scanner;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/13 14:15
 * @Copyright 博为峰
 */
public class LoginService {
    public Scanner scanner;
    public StudentService02 service;

    public LoginService() {
        scanner = new Scanner(System.in);
        service = new StudentService02();
    }

    public void login() {
        System.out.println("1.登录");
        System.out.println("2.退出");
        String choice = scanner.nextLine();
        switch (choice) {
            case "1":
                do {
                    if (verify()) break;
                } while (true);
                showMenu();
                break;
            case "2":
                System.out.println("谢谢使用");
                break;
        }
    }

    public boolean verify() {
        System.out.println("请输入用户名");
        String name = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        if (name.equals("admin") && password.equals("123456")) {
            System.out.println("欢迎使用学生管理系统");
            return true;
        } else {
            System.out.println("用户名或密码错误!!!");
            return false;
        }
    }

    public void showMenu() {
        boolean isExit = false;
        do {
            System.out.println("1.新增");
            System.out.println("2.修改");
            System.out.println("3.删除");
            System.out.println("4.查询");
            System.out.println("5.退出");
            String choice = scanner.nextLine();
            switch (choice) {
                case "1":
                    service.addStu();
                    break;
                case "2":
                    service.updateStu();
                    break;
                case "3":
                    service.deleteStu();
                    break;
                case "4":
                    service.listStu();
                    break;
                case "5":
                    isExit = true;
                    break;
                default:
                    System.out.println("请输入相应的功能");
            }
        } while (!isExit);
    }
}
